package com.lotus.lqmp.service.service.impl;

import com.google.common.collect.Maps;
import com.lotus.lqmp.base.feign.BasicUserDataFeignClient;
import com.lotus.lqmp.base.model.request.MultipleUserInfoQuery;
import com.lotus.lqmp.base.model.response.ThirdSyncUserDTO;
import com.lotus.lqmp.base.third.model.CommonUserDTO;
import com.lotus.lqmp.service.service.UserInfoTransferService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * description
 * @author Shiheng.Liu1
 * @since 2022/04/06 13:46
 */
@Service
public class UserInfoTransferServiceImpl implements UserInfoTransferService {

    @Autowired
    private BasicUserDataFeignClient basicUserDataFeignClient;

    @Override
    public Map<String, CommonUserDTO> getUserInfoByEmployeeNos(List<String> employeeNos) {
        if (employeeNos == null || employeeNos.size() == 0) {
            return Maps.newHashMap();
        }

        MultipleUserInfoQuery query = new MultipleUserInfoQuery();
        query.setEmployeeNos(employeeNos);
        Map<String, ThirdSyncUserDTO> dtoMap = basicUserDataFeignClient.listUserInfoByEmpNos(query).getData();
        Map<String, CommonUserDTO> resultMap = Maps.newHashMap();
        for (Map.Entry<String, ThirdSyncUserDTO> entry : dtoMap.entrySet()) {
            String key = entry.getKey();
            ThirdSyncUserDTO value = entry.getValue();
            CommonUserDTO commonUserDTO = new CommonUserDTO();
            BeanUtils.copyProperties(value, commonUserDTO);
            resultMap.put(key, commonUserDTO);
        }

        return resultMap;
    }
}
